<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link type="text/css" href="/css/start/jquery-ui-1.8.21.custom.css" rel="Stylesheet" />	
<link type="text/css" href="/css/1pxtable.css" rel="Stylesheet" />	
<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.8.21.custom.min.js"></script>

</head>
<body>
<h1>Summary</h1>
<?php 
	$staff = new Model_DbTable_Roster_Stafflogindetail(Zend_Registry::get('db_remoteapp'));
	$partList = array();
	$repairPartsDb = array();
	$serviceTotal = array();
	$array3 = unserialize(ARR_RCENTER_REV_MAPPING);
	sort($array3);
	$array5 = array();
	$bounus = 2;
	$rPartsRecord = new Model_DbTable_Repairstatusrecord(Zend_Registry::get('db_remoteapp'));
	error_reporting(E_ALL ^ E_NOTICE);

	foreach($this->comparePrice as $key => $v){
		
			if($v['shop_name'] == 'BSPC' || $v['shop_name'] == 'BSXP'){
				$repairPartsDb['BSXP'] += $v['qty_product'];
			}
			elseif($v['shop_name'] == 'EPPC' || $v['shop_name'] == 'EPIC'){
				$repairPartsDb['EPPC'] += $v['qty_product'];
			}
			elseif($v['shop_name'] == 'WBIC' || $v['shop_name'] == 'WBPC'){
				$repairPartsDb['WBPC'] += $v['qty_product'];
			}
			elseif($v['shop_name'] == 'WGIC' || $v['shop_name'] == 'WGPC'){
				$repairPartsDb['WGIC'] += $v['qty_product'];
			}
			elseif($v['shop_name'] == 'CLIC' || $v['shop_name'] == 'CLPC'){
				$repairPartsDb['CLPC'] += $v['qty_product'];
			}else{
				$repairPartsDb[$v['shop_name']] += $v['qty_product'];
			}
	}

	foreach($this->repairPartDetail as $key3 => $val3){
		
		if($key3 == 'BSPC' || $key3 == 'BSXP'){
			$bsxp += (int)$val3;
		}
		if($key3 == 'EPPC' || $key3 == 'EPIC'){
			$eppc += (int)$val3;
		}
		if($key3 == 'WBIC' || $key3 == 'WBPC'){
			$wbpc += (int)$val3;
		}
		if($key3 == 'WGIC' || $key3 == 'WGPC'){
			$wgic += (int)$val3;
		}
		if($key3 == 'CLIC' || $key3 == 'CLPC'){
			$clpc += (int)$val3;
		}
		$array5[$key3] = (int)$val3;
		$array5['BSXP'] = $bsxp;
		$array5['BSPC'] = 0;
		$array5['EPPC'] = $eppc;
		$array5['EPIC'] = 0;
		$array5['WBPC'] = $wbpc;
		$array5['WBIC'] = 0;
		$array5['WGIC'] = $wgic;
		$array5['WGPC'] = 0;
		$array5['CLPC'] = $clpc;
		$array5['CLIC'] = 0;
	}
	
	//d($array5);
	

	$ladderArray = array();
	foreach($this->arrRes as $key4 => $val4){
		$rOpen = $rPartsRecord->isJobReopen($val4["id_job"]);
		if(!$rOpen){
			
			if($val4['shop_code'] == 'BSPC' || $val4['shop_code'] == 'BSXP'){
				$ladderArray['BSXP'][$val4['repair_staff']][0] += $val4['bonus_service'];
			}
			elseif($val4['shop_code'] == 'EPPC' || $val4['shop_code'] == 'EPIC'){
				$ladderArray['EPPC'][$val4['repair_staff']][0] += $val4['bonus_service'];
			}
			elseif($val4['shop_code'] == 'WBIC' || $val4['shop_code'] == 'WBPC'){
				$ladderArray['WBPC'][$val4['repair_staff']][0] += $val4['bonus_service'];
			}
			elseif($val4['shop_code'] == 'WGIC' || $val4['shop_code'] == 'WGPC'){
				$ladderArray['WGIC'][$val4['repair_staff']][0] += $val4['bonus_service'];
			}
			elseif($val4['shop_code'] == 'CLIC' || $val4['shop_code'] == 'CLPC'){
				$ladderArray['CLPC'][$val4['repair_staff']][0] += $val4['bonus_service'];
			}else{
				$ladderArray[$val4['shop_code']][$val4['repair_staff']][0] += $val4['bonus_service'];
			}
		}
	}
	//d($ladderArray);
	$perfectbounus = array();
	foreach($this->arrRes as $k9 => $v9){
		$rOpen = $rPartsRecord->isJobReopen($v9["id_job"]);
		if(!$rOpen){
				
			if($v9['shop_code'] == 'BSPC' || $v9['shop_code'] == 'BSXP'){
				$perfectbounus['BSXP'] += $v9['perfect_bonus'];
				$serviceTotal['BSXP'] += $v9['bonus_part'];
			}
			elseif($v9['shop_code'] == 'EPPC' || $v9['shop_code'] == 'EPIC'){
				$perfectbounus['EPPC'] += $v9['perfect_bonus'];
				$serviceTotal['EPPC'] += $v9['bonus_part'];
			}
			elseif($v9['shop_code'] == 'WBIC' || $v9['shop_code'] == 'WBPC'){
				$perfectbounus['WBPC'] += $v9['perfect_bonus'];
				$serviceTotal['WBPC'] += $v9['bonus_part'];
			}
			elseif($v9['shop_code'] == 'WGIC' || $v9['shop_code'] == 'WGPC'){
				$perfectbounus['WGIC'] += $v9['perfect_bonus'];
				$serviceTotal['WGIC'] += $v9['bonus_part'];
			}
			elseif($v9['shop_code'] == 'CLIC' || $v9['shop_code'] == 'CLPC'){
				$perfectbounus['CLPC'] += $v9['perfect_bonus'];
				$serviceTotal['CLPC'] += $v9['bonus_part'];
			}else{
				$perfectbounus[$v9['shop_code']] += $v9['perfect_bonus'];
				$serviceTotal[$v9['shop_code']] += $v9['bonus_part'];
			}
		}
	}
	
	foreach($array5 as $k7 => $v7){
			$mytotal[$k7] = $v7;
			$partsPerfectTotal[$k7] = $v7;
		foreach($repairPartsDb as $k8 => $v8){
			
			if($k7 == $k8 ){
				if($v7 >= $v8){
					$mytotal[$k7] = $v8;
					$partsPerfectTotal[$k7] = $v7;
				}else{
					$partsPerfectTotal[$k7] = $v8;
				}
			}
		}
	}

?>
<table width="1000" border="1" cellspacing="0" cellpadding="15">
<tr>
	<th>Shop</th>
	<th>Repair Parts qty(APOS BY RC)</th>
	<th>Repair Parts(DATABASE BY RC)</th>
	<th>Service Total</th>
	<th>All Total</th>
	<th>Perfect Parts Total</th>
	<th>Perfect Service Total</th>
	<th>Perfect Total</th>
	<th width = "200">Top Repair Staff</th>
</tr>

	<?php foreach($array3 as $key => $v){
			$test = 0;
	    	$test2 = 0;
	    	$total = 0;
	    	$perfectTotal = 0;?>
	<tr>
		<td><?php echo $v;?></td>
		<td><?php foreach ($array5 as $k5 => $v5){
			$test5 = 0;
			if($v == $k5){
				$test5 = 1;
				break;
			}else{
				$test5 = 0;
			}
			}
			if($test5 != 0){
				echo $v5;
			}
			else{
				echo "0";
			}
		?></td>
		<td><?php 	
				foreach ($repairPartsDb as $k3 => $v3){
					$test3 = 0;
					if( $v == $k3){
							$test3 = 1;
							break;
						}else{
							$test3 = 0;
						}
					}
					if($test3 != 0){
						echo $v3;
					}
					else{
						echo "0";
					}?></td>
			
		<?php foreach($mytotal as $k6 => $v6){
					$test6 = 0;
						if($v == $k6){
							$test6 = 1;
							break;
						}else{
							$test6 = 0;
						}	
				}
					if($test6 != 0){
						$total += $v6;
					}

			?>					
		<td><?php 	
				foreach ($serviceTotal as $k2 => $v2){
					$test2 = 0;
					if($v == $k2){
							$test2 = 1;
							break;
						}else{
							$test2 = 0;
						}
					}
					if($test2 != 0){
						echo $v2;
						$total += $v2;
					}
					else{
						echo "0";
					}?></td>
		<td><?php echo $total;?></td>
		
		<td><?php foreach($partsPerfectTotal as $k4 => $v4){
				$test4 = 0;
					if($v == $k4){
						$test4 = 1;
						break;
					}else{
						$test4 = 0;
					}
				}
				if($test4 != 0){
					echo $v4;
					$perfectTotal += $v4;
				}
		?></td>
		<td><?php foreach($perfectbounus as $k10 => $v10){
				$test10 = 0;
					if($v == $k10){
						$test10 = 1;
						break;
					}else{
						$test10 = 0;
					}
				}
				if($test10 != 0){
					echo $v10;
					$perfectTotal += $v10;
				}?></td>
		<td><?php echo $perfectTotal;?></td>
		<td><?php foreach($ladderArray as $key8 => $val8){
				arsort($val8);
				$i = 1;
				$test7 = 0;
				if($v == $key8){
					$test7 = 1;
					break;
				}else{
					$test7 = 0;
				}
				}
				if($test7 != 0){
					foreach($val8 as $key9 => $val9){
						
						$staffInfo = $staff->getDetail($key9);
						
						echo $i++.':'.$staffInfo['ni'].'    '.$val9[0].'<br/>';
					}
				}
				else{
					echo "Null";
		}?></td>
</tr>
<?php }?>




</table>


</body>
</html>
